<template>
  <div>
    <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model.trim="content" />
    <br><br>
    <el-button type="primary" @click="onSubmit">提交留言</el-button>
    <el-button type="primary" @click="logout">退出登录</el-button>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import router from '@/router'
// 父组件监听 addComment 事件
const emit = defineEmits(['addComment'])
const content = ref('')

function onSubmit() {
  if (!content.value) return
  emit('addComment', content.value)//触发父组件函数
  content.value = ''
}

function logout() {
  window.sessionStorage.removeItem('currentUserName')
  alert('退出登录!')
  setTimeout(() => router.push('/login'), 50)
}
</script>
